<?php

namespace app\home\controller;
use think\Request;
use think\facade\Cookie;
class Comment extends BaseController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */

    // protected $updateTime = 'time';

    public function index()
    {
        
    }
    //评论
    public function send()
    {
        # code...
        if (request()->isPost()) {
            $data = [
                'content' => input('content'),
                'userid' => Cookie::get('userid'),
                'pid' => input('pid'),
                'time' => date('Y-m-d H:i:s')
            ];
            $info = model('Classes')->find(input('pid'));
            $result = model('Comment')->send($data);
            if ($result == 1) {
                $info->setInc('comments');
                // return json(array('code' => 1, 'msg' => '发表成功'));
                return json(array('code'=> 200,'msg' => '评论成功'));
            } else {
                return json(array('code'=> 100,'msg' => $result));
            }
        }
    }
}
